package com.zero.rocketmq.api.base.customer;

import com.zero.rocketmq.api.utils.RocketMQContents;
import org.apache.rocketmq.client.consumer.DefaultLitePullConsumer;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.common.consumer.ConsumeFromWhere;
import org.apache.rocketmq.common.message.MessageExt;

import java.util.List;

public class LitePullConsumerSubscribe {

    public static void main(String[] args) throws MQClientException {

        DefaultLitePullConsumer consumer = new DefaultLitePullConsumer(RocketMQContents.CUSTOMER_GROUP);
        consumer.setNamesrvAddr(RocketMQContents.NAMESERVER_ADDR);
        consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
        consumer.start();

        consumer.subscribe(RocketMQContents.TOPIC,"*");
        try {
            while (true){
                List<MessageExt> messageExts = consumer.poll();
                System.out.printf("%s%n", messageExts);
            }
        }finally {
            consumer.shutdown();
        }

    }
}
